/**
 * @description 数据类型
 * @readonly
 * @enum {String}
 */
export const DataType = {
  Object: "Object",
  Array: "Array",
  Function: "Function",
  String: "String",
  Number: "Number",
  Boolean: "Boolean",
  Undefined: "Undefined",
  Null: "Null",
  Symbol: "Symbol",
  BigInt: "BigInt",
  Map: "Map",
  Set: "Set",
  WeakMap: "WeakMap",
  WeakSet: "WeakSet",
  Date: "Date",
  Error: "Error",
  Window: "Window",
  Global: "Global",
  RegExp: "RegExp",
};

/**
 * @description 类型映射表
 * @readonly
 * @type {Map<string,DataType>}
 */
const DataTypeMap = new Map([
  ["[object Object]", DataType.Object],
  ["[object Array]", DataType.Array],
  ["[object Function]", DataType.Function],
  ["[object String]", DataType.String],
  ["[object Number]", DataType.Number],
  ["[object Boolean]", DataType.Boolean],
  ["[object Undefined]", DataType.Undefined],
  ["[object Null]", DataType.Null],
  ["[object Symbol]", DataType.Symbol],
  ["[object BigInt]", DataType.BigInt],
  ["[object Map]", DataType.Map],
  ["[object Set]", DataType.Set],
  ["[object WeakMap]", DataType.WeakMap],
  ["[object WeakSet]", DataType.WeakSet],
  ["[object Date]", DataType.Date],
  ["[object Error]", DataType.Error],
  ["[object Window]", DataType.Window],
  ["[object Global]", DataType.Global],
  ["[object RegExp]", DataType.RegExp],
]);

/**
 * @description 判断数据类型
 * @param {any} obj
 * @returns {DataType}
 */
export const determineDataType = (obj) =>
  DataTypeMap.get(Object.prototype.toString.call(obj));
